
$(document).ready(function(){
	loadDictionaries();
});



	/**
	 * 数据字典表
	 */
	function loadDictionaries(){
		$("#dictContainer").jtable({
			//title:"数据字典表",
			paging:true,
			pageSize:10,
			gotoPageArea:'none',
			columnSelectable: false,//右击列表头显示列
			pageSizeChangeArea:false,
			selectingCheckboxes:false,
			selecting: true, //Enable selecting
            multiselect: false, //Allow multiple selecting
            //selectOnRowClick: false, //Enable this to only select using checkboxes
			actions:{
				listAction:appCtx +"secure/dictionary/qryPageDictionaries.html"
			},
			fields:{
				dictId:{
					key:true,
					list:false
				},
				dictName:{
					title:"字典名称",
					width:"10%"
				},
				dictCode:{
					title:"字典编码",
					width:"10%"
				},
				dictDesc:{
					title:"字典描述",
					width:"10%"
				},
				operation:{
					title:"操作",
					width:"5%",
					userData:true,
					content:$("#operationDict").html(),
					param:"dictId,dictName"
				}
			},
			 selectionChanged:selectionChanged
		});
		
		queryDict();
	}

	function queryDict(){
		var params = $("#queryDictForm").serialize();
		$("#dictContainer").jtable("load",params);
	}
	
	/**
	 * 弹出新增对话框
	 * */
	function showModal(){
		var url = appCtx+"secure/dictionary/initDictionary.html";
		$.post(url,function(data){
			$("#title").html("新增");
			$("#dictModal .modal-body").html(data);
		});
		$("#dictModal").modal();
	}
	
	 function saveDict(){ 
		 var flag = $("#dictForm").validationAjax();
			if(flag){
				var url = appCtx+"secure/dictionary/saveDictionary.html";
				var params = $("#dictForm").serialize();
				$.post(url,params,function(data){
					$("#dictContainer").jtable("reload");
					$("#dictModal").modal("hide");
				});
			}
			return flag;
	 }


	 function updateDict(dictId){
		var url = appCtx+"secure/dictionary/updateDictionary.html";
		$.post(url,{dictId:dictId},function(data){
			$("#title").html("修改");
			$("#dictModal .modal-body").html(data);
		});
		$("#dictModal").modal();
		
	}
	 
	 
	function deleteDict(dictId,dictName){
		var url=appCtx+"secure/dictionary/delDictionary.html";
		if(window.confirm("确定删除["+dictName+"]吗?")){
			$.post(url,{dictId:dictId},function(data){
				$("#dictContainer").jtable("reload");
			});
		}
	}
	
	//选中行
	function selectionChanged(event, data){
		var selectedRows = $('#dictContainer').jtable('selectedRows');
		selectedRows.each(function () {
		    var record = $(this).data('record');
		    var dictId = record.dictId;
		    loadPageAjax('0123456789','字典条目管理',"secure/dictItem/listDictItem.html?dictId="+dictId);
		});
	}

	